#include "widget.h"
#include "ui_widget.h"

#include <QTcpSocket>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    tcpServer = new QTcpServer(this);
    // bind地址 处于监听状态
    tcpServer->listen(QHostAddress("10.11.17.59"), 1234);
    // 当c端连接触发信号
    connect(tcpServer, &QTcpServer::newConnection, this, &Widget::connectSlots);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::connectSlots()
{
    // 接收连接
    QTcpSocket *newServer = tcpServer->nextPendingConnection();
    newServer->write("hello world");
    newServer->close();

}
